#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>

#define FOR(i,a,n) for(int i=a;i<n;++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int dp[330][33];
int dis[330][330];
int v,p;
int pos[330];

void init()
{
    FOR(len,0,v) FOR(vs,1,v-len+1)
    {
        dis[vs][vs+len] = pos[vs+len]-pos[vs];
        if(len>2)
        {
            dis[vs][vs+len]+=dis[vs+1][vs+len-1];
        }
    }
    FOR(vi,1,v+1) FOR(pi,1,p+1) dp[vi][pi] = 1<<29;
    FOR(vi,1,v+1) dp[vi][1] = dis[1][vi];
    REP(pi,p+1) dp[1][pi]=0;
}
int main()
{
    scanf("%d%d",&v,&p);
    REP(i,v) scanf("%d",pos+i+1);
    init();
    FOR(pi,2,p+1) FOR(vi,2,v+1)
    {
        FOR(k,1,vi) dp[vi][pi]=min(dp[vi][pi],dp[k][pi-1]+dis[k+1][vi]);
    }
    printf("%d\n",dp[v][p]);
    return 0;
}
